import got from "got";

async function getPayData_bgfr(u) {
  const sign = u.searchParams.get("sign");
  const res = await got({
    url: "http://admin.bgfr.cc/starbucks/api/orderPayWithValidation",
    searchParams: { sign },
    method: "GET",
  });
  const body = JSON.parse(res.body);
  if (body?.data?.biz_content) {
    return body.data.biz_content;
  }
  console.error(res.body);
  throw new Error("获取支付地址失败");
}

async function getDefaultPayData(u) {
  const sign = u.searchParams.get("sign");
  const res = await got({
    url: u.origin + "/mop/Srkit2000022080",
    searchParams: { sign },
    method: "POST",
  });
  const body = JSON.parse(res.body);
  if (body?.pay) {
    return body.pay;
  }
  console.error(res.body);
  throw new Error("获取支付地址失败");
}

export default {
  "qd.bgfr.cc": getPayData_bgfr,
  default: getDefaultPayData,
};
